<template>
    <SysDialog draggable :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
    <!-- 内容组件 -->
      <el-form :model="dialogModel" ref="addDeptForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="name" label="部门名称">
          <el-input v-model="dialogModel.name" clearable></el-input>
        </el-form-item>
        <el-form-item prop="parentId" label="上级部门">
          <el-input v-model="dialogModel.parentId" clearable></el-input>
        </el-form-item>
      </el-form>
    </template>
  </SysDialog>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import {ElForm} from 'element-plus'
import SysDialog from '@/components/SysDialog.vue';
import useDialog from '@/hooks/useDialog';
import useInstance from '@/hooks/useInstance';
import depeModel from '@/composables/03organization/02department/depeModel'
import { EditType, Title } from '@/type/BaseEnum'
// 使用
const { dialog, onClose, onShow } = useDialog()
const { global, proxy } = useInstance();
const {rules, dialogModel} =depeModel()
const addDeptForm = ref<InstanceType<typeof ElForm>>()
// 父级数据
// const props = defineProps({
 
// })
// 保存
const emit = defineEmits(['save'])
const confirm=()=>{
  // 数据校验
  addDeptForm?.value?.validate((isOk)=>{
    if(isOk){
      console.log('嗯嗯');
      
      emit('save',dialogModel)
      onClose()
    }
  })
}
const show = (type: string, row?:any) => {
  console.log('show');
  dialog.width = 650
  dialog.height = 150
  // dialog.title='新增'
  dialog.title= type==EditType.ADD?Title.ADD:Title.EDIT

  onShow()
  global.$resetForm(addDeptForm.value,dialogModel)
  if(type === EditType.EDIT){
    global.$objCopy(row,dialogModel)
  }
}
defineExpose({
  show
})
</script>
<style scoped lang='scss'>
</style>